<?php
namespace app\index\controller;
use app\common\controller\Homebase;

class Rule extends Homebase
{
    public function rule(){

        $datalist = Db('auth_group')->select();
        $this->assign('datalist',$datalist);
        return $this->fetch();
    }

    public function editrole(){
        $id = $this->request->param('id');
        $data = Db('auth_group')->where('id',$id)->find();
        $this->assign('data',$data);
        return $this->fetch();
    }

    public function editrolepost(){
        $data = $this->request->param();
        $result = Db('auth_group')->where('id',$data['id'])->update(['title'=>$data['title']]);
        if ($result!==false) {
            return array('status' => 1,'info'=>'修改成功');
        }
    }

    public function delrule(){
        $id = $this->request->param('id');
        $result = Db('auth_group')->delete($id);
        if ($result) {
           return array('status' => 1,'info'=>'删除成功');
        }
    }

    public function addrule(){
    	$name = $this->request->post('name');
    	$data['title']   = $name;
    	$data['module']  = 'admin';
    	$data['create_time']   = time();
    	$data['update_time']   = time();
    	$result = Db('auth_group')->insert($data);
        if ($result) {
            return array('status' => 1,'info'=>'添加成功');
        }
    }


    public function juris(){
        return $this->fetch();
    }

}
